package contract.jvm.instructions;

import contract.jvm.Frame;
import contract.jvm.Jvm;
import contract.jvm.Reference;
import org.objectweb.asm.tree.FieldInsnNode;

public class Getfield {

    /**
     * 获取对象字段的值，把值推入操作数栈顶
     */
    public static void getfield(Jvm jvm) {
        Frame frame = jvm.jvmStack.lastElement();
        FieldInsnNode fieldInsnNode = (FieldInsnNode) jvm.pc.currentInsnNode;
        String fieldName = fieldInsnNode.name;

        Reference reference = (Reference) frame.operandStack.pop();
        Object value = jvm.heap.getField(reference, fieldName);
        frame.operandStack.push(value);
    }

}
